package com.yc.pay.service.impl;

import com.alibaba.fastjson.JSON;
import com.yc.pay.constant.RedisKeyConstant;
import com.yc.pay.mapper.MchPayWayMapper;
import com.yc.pay.model.MchPayWay;
import com.yc.pay.service.IMchPayWayService;
import com.yc.pay.service.JedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * 商户支付接口实现类
 */
@Service
public class MchPayWayServiceImpl implements IMchPayWayService {

//    @Autowired
//    private IMchPayWayService mchPayWayService;

    @Autowired
    private ValueOperations valueOperations;

    @Autowired
    private MchPayWayMapper payWayMapper;

    @Override
    public MchPayWay queryByMchIdAndPayWay(String mchId, String payWay) {

        MchPayWay mchPayWay = (MchPayWay)valueOperations.get(RedisKeyConstant.MCH_PAY_WAY_KEY + mchId + ":"+ payWay);
        if (ObjectUtils.isEmpty(mchPayWay)){
             mchPayWay = payWayMapper.queryByMchIdAndPayWay(mchId,payWay);
            valueOperations.set(RedisKeyConstant.MCH_PAY_WAY_KEY + mchId + ":"+ payWay, mchPayWay);
        }

        return mchPayWay;
    }
}
